package com.msite.web
import com.msite.framework.JsonResult
import com.msite.framework.PageResult
import com.msite.model.SysUser
import com.msite.model.param.SysUserParam
import com.msite.service.SysUserService
import org.springframework.stereotype.Controller
import org.springframework.ui.ModelMap
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody

import javax.annotation.Resource
import javax.servlet.http.HttpServletRequest
/**
 * Created by tpeng on 2015/12/3.
 */
@Controller
class SysUserController extends BaseController{

    @Resource
    private SysUserService sysUserService;

    @RequestMapping(value = "/sysuser/list")
    String index(ModelMap model){
        "/sysuser/sysuser_list";
    }

    @RequestMapping(value = "/sysuser/list/data")
    @ResponseBody
    PageResult list(HttpServletRequest request, SysUserParam param, ModelMap model){
       sysUserService.getSysUserVoListByPage(param)
    }

    /* test
    @RequestMapping(value = "/sa/sysuser/edit_")
    public String edit_(ModelMap model){
        return "/bak_/edit_test";
    }*/

    @RequestMapping(value = "/sysuser/edit_")
    public String edit_(ModelMap model){
        model.put("RoleListJsonData", sysUserService.selectRoleListJsonData());
        return "/sysuser/sysuser_edit";
    }

    @RequestMapping(value = "/sysuser/modify")
    @ResponseBody
    JsonResult info(HttpServletRequest request, ModelMap model, SysUser sysUser){
        if(sysUser.id && sysUser.id > 0){
            sysUserService.updateByPrimaryKeySelective(sysUser);
        }else{
            sysUserService.insertSelective(sysUser)
        }
        new JsonResult(code: JsonResult.CODE_OK, msg: "")
    }

}
